package com.surelution.projects.crm

class NoGasTypeController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index = {
        redirect(action: "list", params: params)
    }

    def list = {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        [noGasTypeInstanceList: NoGasType.list(params), noGasTypeInstanceTotal: NoGasType.count()]
    }

    def create = {
        def noGasTypeInstance = new NoGasType()
        noGasTypeInstance.properties = params
        return [noGasTypeInstance: noGasTypeInstance]
    }

    def save = {
        def noGasTypeInstance = new NoGasType(params)
        if (noGasTypeInstance.save(flush: true)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'noGasType.label', default: 'NoGasType'), noGasTypeInstance.id])}"
            redirect(action: "show", id: noGasTypeInstance.id)
        }
        else {
            render(view: "create", model: [noGasTypeInstance: noGasTypeInstance])
        }
    }

    def show = {
        def noGasTypeInstance = NoGasType.get(params.id)
        if (!noGasTypeInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'noGasType.label', default: 'NoGasType'), params.id])}"
            redirect(action: "list")
        }
        else {
            [noGasTypeInstance: noGasTypeInstance]
        }
    }

    def edit = {
        def noGasTypeInstance = NoGasType.get(params.id)
        if (!noGasTypeInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'noGasType.label', default: 'NoGasType'), params.id])}"
            redirect(action: "list")
        }
        else {
            return [noGasTypeInstance: noGasTypeInstance]
        }
    }

    def update = {
        def noGasTypeInstance = NoGasType.get(params.id)
        if (noGasTypeInstance) {
            if (params.version) {
                def version = params.version.toLong()
                if (noGasTypeInstance.version > version) {
                    
                    noGasTypeInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'noGasType.label', default: 'NoGasType')] as Object[], "Another user has updated this NoGasType while you were editing")
                    render(view: "edit", model: [noGasTypeInstance: noGasTypeInstance])
                    return
                }
            }
            noGasTypeInstance.properties = params
            if (!noGasTypeInstance.hasErrors() && noGasTypeInstance.save(flush: true)) {
                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'noGasType.label', default: 'NoGasType'), noGasTypeInstance.id])}"
                redirect(action: "show", id: noGasTypeInstance.id)
            }
            else {
                render(view: "edit", model: [noGasTypeInstance: noGasTypeInstance])
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'noGasType.label', default: 'NoGasType'), params.id])}"
            redirect(action: "list")
        }
    }

    def delete = {
        def noGasTypeInstance = NoGasType.get(params.id)
        if (noGasTypeInstance) {
            try {
                noGasTypeInstance.delete(flush: true)
                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'noGasType.label', default: 'NoGasType'), params.id])}"
                redirect(action: "list")
            }
            catch (org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'noGasType.label', default: 'NoGasType'), params.id])}"
                redirect(action: "show", id: params.id)
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'noGasType.label', default: 'NoGasType'), params.id])}"
            redirect(action: "list")
        }
    }
}
